<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

/**
 * 租借单车控制器
 */
class Lease extends AdminBase
{
    
    /**
     * 租借单车列表
     */
    public function leaseList()
    {
        
        $this->assign('list', $this->logicLease->getLeaseList());
        
        return $this->fetch('lease_list');
    }
    
    /**
     * 租借单车添加
     */
    public function leaseAdd()
    {
        
        IS_POST && $this->jump($this->logicLease->leaseEdit($this->param));
        
        return $this->fetch('lease_edit');
    }
    
    /**
     * 租借单车编辑
     */
    public function leaseEdit()
    {
        
        IS_POST && $this->jump($this->logicLease->leaseEdit($this->param));
        
        $info = $this->logicLease->getLeaseInfo(['id' => $this->param['id']]);
        
        //计算时间差
        $hour = ceil((strtotime($info['end_time'])-strtotime($info['begin_time']))/3600);
        
        //获取到单车租金
        $a = $this->logicLease->getLeaseList();
        foreach ($a as $key => $value) {
        };
        $money = $value['money'] . PHP_EOL;
        
        //计算消费金额
        $pay = (int)$money * (int)$hour;
        $info['pay'] = $pay;

        $this->assign('info', $info);
        
        return $this->fetch('lease_edit');
    }
    
    /**
     * 租借单车删除
     */
    public function leaseDel($id = 0)
    {
        
        $this->jump($this->logicLease->leaseDel(['id' => $id]));
    }
}
